package eleventh.对象克隆技术;
class Person implements Cloneable{
    private String name=null;

    public Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();   //具体的克隆操作由父类完成
    }

    @Override
    public String toString() {
        return "姓名："+this.getName();
    }
}
public class 对象的克隆操作 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person p1 = new Person("王境泽");
        Person p2 = (Person) p1.clone();
        p2.setName("小马云");
        System.out.println("原始对象："+p1);
        System.out.println("克隆之后的对象："+p2);
    }
}
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=56728:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 eleventh.对象克隆技术.对象的克隆操作
原始对象：姓名：王境泽
克隆之后的对象：姓名：小马云

Process finished with exit code 0

 */